package com.itheima.Demo2hashmap;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapDemo2 {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("小王", 18);
        map.put("小张", 19);
        map.put("小李", 20);
        map.put("小王", 28);
        System.out.println(map);
        //获取所有键
        Set<String> keys = map.keySet();
        //遍历所有键
        for (String key : keys) {
            //根据键去找值
            Integer value = map.get(key);
            System.out.println(key+"="+value);
            //遍历方式二：键值对遍历
            Set<Map.Entry<String, Integer>> entries = map.entrySet();
            for (Map.Entry<String, Integer> stringIntegerEntry : entries) {
                String key1 = stringIntegerEntry.getKey();
                Integer value1 = stringIntegerEntry.getValue();

            }
        }
    }
    }

